//  this library.
import 'package:flutter/material.dart';
import 'package:hktk_app/decoration/mine/my_tab_bar_decoration.dart';
import 'package:hktk_app/model/home/column_model.dart';
import 'package:hktk_app/util/font_util.dart';
import 'package:hktk_app/util/view_util.dart';

/// 我的页面tab切换组件
class MyTabBarWidget extends StatelessWidget {
  /// tab的滑动控制，延时初始化，在init里面初始化
  final TabController tabController;

  final List<ColumnModel> list;

  const MyTabBarWidget({
    super.key,
    required this.tabController,
    required this.list,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 80,
      padding:
      EdgeInsets.only(left: 20, right: 20, bottom: 13, top: 13),
      decoration: const BoxDecoration(color: colorWhite2),
      child: Center(
        child: _tabBarItem(),
      ),
    );
  }

  /// 显示选择组件
  _tabBarItem() {
    return TabBar(
      controller: tabController,
      tabs: _myTabs(),
      // tab是否可以在水平方向上滚动
      isScrollable: true,
      // 从左到右进行排列，设置tab左侧对齐，去除左侧偏移
      tabAlignment: TabAlignment.start,
      // 指示器自定义
      indicator: MyTabBarDecoration(),
      // 指示器的内边距
      // indicatorPadding: EdgeInsets.only(top: 8),
      // 分隔线高度
      dividerHeight: 0,
      // tab间距修改
      labelPadding: EdgeInsets.zero,
      // 点击监听
      // onTap: (index) {
      //   debugPrint("index ===> $index");
      // },
    );
  }

  /// tab标签显示
  _myTabs() {
    List<Tab> tabs = [];
    for (int i = 0; i < list.length; i++) {
      ColumnModel model = list[i];
      tabs.add(Tab(
        child: Padding(
          padding: EdgeInsets.only(left: 20, right: 20),
          child: Text(
            model.name!,
            style: FontUtil.fontBlack1(20),
          ),
        ),
      ));
    }
    // for (ColumnModel value in list) {
    //   tabs.add(Tab(
    //     child: Text(
    //       value.name!,
    //       style: FontUtil.fontBlack1(28),
    //     ),
    //   ));
    // }
    return tabs;
  }
}
